package br.com.logics;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;
import org.springframework.beans.factory.annotation.Autowired;

import br.com.dao.DAO;
import br.com.models.User;

public class LoginLogic {
		
	public User executeLogin(User user) {
		
		DetachedCriteria query = DetachedCriteria.forClass(User.class)
				.add(Property.forName("email").eq(user.getEmail()));
		
		DAO<User> userDAO = new DAO<User>();
				
		User userDB = userDAO.searchModel(query);
				
		if(userDB != null) {
					
			if(userDB.getPassword().equals(user.getPassword())) {
				
				return userDB;
			}
		}
		
		return null;
	}
}
